package com.itheima.edu.info.manger.service;

import com.itheima.edu.info.manger.dao.TeacherDao;
import com.itheima.edu.info.manger.domain.Teacher;

public class TeacherService {
    private static TeacherDao teacherDao=new TeacherDao();
    public static boolean addTeacher(Teacher teach) {
       return teacherDao.addTeacher(teach);
    }

    public static boolean getExits(String id) {
        Teacher[] teachers=teacherDao.getAllTeacher();
        for (int i = 0; i < teachers.length; i++) {
            Teacher teacher = teachers[i];
            if (teacher!=null&&teacher.getId().equals(id)){
                return true;
            }
        }
        return false;
    }

    public static Teacher[] getAllTeacher() {
        Teacher[] teachers=teacherDao.getAllTeacher();
        boolean flag=false;
        for (int i = 0; i < teachers.length; i++) {
            Teacher teacher=teachers[i];
            if (teacher!=null) {
                flag = true;
                break;
            }
        }
        if (flag){
            return teachers;
        }else{
            return null;
        }
    }

    public static void deleteTeacherById(String did) {
        teacherDao.deteleTeacherById(did);
    }

    public static void updateTeacher(Teacher newTeacher ,String uid) {
        teacherDao.updateTeacher(newTeacher,uid);
    }
}
